package kr.hkit.powerjava.chapter17;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class ImageLabel extends JPanel {
	
	private JLabel lblNewLabel;
	private JButton btnNewButton;
	private JPanel panelImage;
	
	public ImageLabel() {
		initialize();
	}

	private void initialize() {
		setLayout(new BorderLayout(0,0));
		
		panelImage = new JPanel();
		panelImage.setLayout(new BorderLayout(0, 0));
		
		lblNewLabel = new JLabel("이미지를 보려면 아래 버튼을 누르세요");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		add(lblNewLabel, BorderLayout.CENTER);
		
		
		btnNewButton = new JButton("이미지 레이블");
		add(btnNewButton, BorderLayout.SOUTH);
		btnNewButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (lblNewLabel.getIcon() == null) {
					ImageIcon icon = new ImageIcon("111.jpg");
					lblNewLabel.setIcon(icon);
					lblNewLabel.setText(null);
				} else {
					lblNewLabel.setIcon(null);
					lblNewLabel.setText("이미지를 보려면 아래 버튼을 누르세요");
				}
			}
		});
		
		
	}

}
